package com.xtravel.common.helper;

import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;

import java.lang.reflect.Type;

public class JsonHelper {
	public static String toJson(Object object, Type type) {
		Gson gson = new Gson();
		return gson.toJson(object, type);
	}

	public static <T> T fromJson(String json, Class<T> clazz) {
		Gson gson = new Gson();
		return gson.fromJson(json, clazz);
	}

	public static <T> T fromJson(String json, TypeToken<T> typeToken) {
		Gson gson = new Gson();
		return gson.fromJson(json, typeToken.getType());
	}
}
